<tr>
    {# Drop key anchor #}
    <td>
        {% set js_msg = '' %}
        {% set this_params = null %}
        {% if one_key.constraint is defined %}
            {% set drop_fk_query = 'ALTER TABLE ' ~ backquote(db) ~ '.' ~ backquote(table)
                ~ ' DROP FOREIGN KEY '
                ~ backquote(one_key.constraint) ~ ';'
            %}
            {% set this_params = url_params %}
            {% set this_params = {
                'goto': url('/table/relation'),
                'back': url('/table/relation'),
                'sql_query': drop_fk_query,
                'message_to_show': t('Foreign key constraint %s has been dropped')|format(
                    one_key.constraint
                )
            } %}
            {% set js_msg = 'ALTER TABLE ' ~ db ~ '.' ~ table ~ ' DROP FOREIGN KEY ' ~ one_key.constraint ~ ';' %}
        {% endif %}
        {% if one_key.constraint is defined %}
            <input type="hidden" class="drop_foreign_key_msg" value="
                {{- js_msg }}">
            {% set drop_str = get_icon('b_drop', t('Drop')) %}
            {{ link_or_button(url('/sql'), this_params, drop_str, {'class': 'drop_foreign_key_anchor ajax'}) }}
        {% endif %}
    </td>
    <td>
        <span class="clearfloat">
            <input type="text" name="constraint_name[{{ i }}]" value="
                {{- one_key.constraint is defined ? one_key.constraint -}}
                " placeholder="{{ t('Constraint name') }}" maxlength="64">
        </span>
        <div class="float-start">
            {# For ON DELETE and ON UPDATE, the default action
               is RESTRICT as per MySQL doc; however, a SHOW CREATE TABLE
               won't display the clause if it's set as RESTRICT. #}
            {% set on_delete = one_key.onDelete is defined
                ? one_key.onDelete : 'RESTRICT' %}
            {% set on_update = one_key.onUpdate is defined
                ? one_key.onUpdate : 'RESTRICT' %}
            <span>
                {% include 'table/relation/dropdown_generate.twig' with {
                    'dropdown_question': 'ON DELETE',
                    'select_name': 'on_delete[' ~ i ~ ']',
                    'choices': options_array,
                    'selected_value': on_delete
                } only %}
            </span>
            <span>
                {% include 'table/relation/dropdown_generate.twig' with {
                    'dropdown_question': 'ON UPDATE',
                    'select_name': 'on_update[' ~ i ~ ']',
                    'choices': options_array,
                    'selected_value': on_update
                } only %}
            </span>
        </div>
    </td>
    <td>
        {% if one_key.indexList is defined %}
            {% for key, column in one_key.indexList %}
                <span class="clearfloat">
                    {% include 'table/relation/dropdown_generate.twig' with {
                        'dropdown_question': '',
                        'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
                        'choices': column_array,
                        'selected_value': column
                    } only %}
                </span>
            {% endfor %}
        {% else %}
            <span class="clearfloat">
                {% include 'table/relation/dropdown_generate.twig' with {
                    'dropdown_question': '',
                    'select_name': 'foreign_key_fields_name[' ~ i ~ '][]',
                    'choices': column_array,
                    'selected_value': ''
                } only %}
            </span>
        {% endif %}
        <a class="clearfloat add_foreign_key_field" data-index="
            {{- i }}" href="">
            {{ t('+ Add column') }}
        </a>
    </td>
    <td>
        <span class="clearfloat">
            {% include 'table/relation/relational_dropdown.twig' with {
                'name': 'destination_foreign_db[' ~ i ~ ']',
                'title': t('Database'),
                'values': databases,
                'foreign': foreign_db,
                'db': db
            } only %}
        </span>
    </td>
    <td>
        <span class="clearfloat">
            {% include 'table/relation/relational_dropdown.twig' with {
                'name': 'destination_foreign_table[' ~ i ~ ']',
                'title': t('Table'),
                'values': tables,
                'foreign': foreign_table
            } only %}
        </span>
    </td>
    <td>
        {% if foreign_table is not same as ( '' ) %}
            {% for foreign_column in one_key.refIndexList %}
                <span class="clearfloat">
                    {% include 'table/relation/relational_dropdown.twig' with {
                        'name': 'destination_foreign_column[' ~ i ~ '][]',
                        'title': t('Column'),
                        'values': unique_columns,
                        'foreign': foreign_column
                    } only %}
                </span>
            {% endfor %}
        {% else %}
            <span class="clearfloat">
                {% include 'table/relation/relational_dropdown.twig' with {
                    'name': 'destination_foreign_column[' ~ i ~ '][]',
                    'title': t('Column'),
                    'values': [],
                    'foreign': ''
                } only %}
            </span>
        {% endif %}
    </td>
</tr>
